package com.baidu.cmsService.services.impls;

import com.baidu.cmsCommes.pojo.Role;
import com.baidu.cmsCommes.pojo.RoleType;
import com.baidu.cmsService.dao.RoleDao;
import com.baidu.cmsService.dao.UserRoleDao;
import com.baidu.cmsService.services.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: BSS
 * @create: 2020/6/18/15:15
 */
@Service

public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleDao roleDao;

    @Resource
    private UserRoleDao userRoleDao;

    public List<Role> roleList() {
        return roleDao.roleList();
    }

    public List<String> getAllType() {
        List<String> typeList = new ArrayList<String>();
        typeList.add(RoleType.ROLE_ADMIN.toString());
        typeList.add(RoleType.ROLE_AUDIT.toString());
        typeList.add(RoleType.ROLE_PUBLISH.toString());
        return typeList;
    }

    public Boolean saveRole(Role role) {
        return roleDao.saveRole(role)==null?false:true;
    }

    public Boolean deleteRole(Integer rid) {
        return roleDao.deleteRole(rid)==null?false:true;
    }

    public Role selectById(Integer rid) {
        return roleDao.selectById(rid);
    }

    public Boolean updateRole(Role role) {
        return roleDao.updateRole(role)==null?false:true;
    }

    public Boolean deleteUserRole(Integer rid) {
        return userRoleDao.deleteRoleByRid(rid)!=null?true:false;
    }
}
